#!/bin/bash

get_char()
        {
        SAVEDSTTY=`stty -g`
        stty -echo
        stty cbreak
        dd if=/dev/tty bs=1 count=1 2> /dev/null
        stty -raw
        stty echo
        stty $SAVEDSTTY
        }

echo "此脚本用于将IPA上传至www.pgyer.com和BuildBrowser，并下载二维码。（当前路径不得有空格）"
echo "请输入版本号（例如0.4.2）： "
read Version
echo "请输入build号（例如31）： "
read BuildNumber
echo "请输入要放人buildbrowser的分支，例如main或rel_1.2.0 : "
read Branch

BuildDir="${Branch}/${Version}/${Version}#${BuildNumber}-`date +%y%m%d%H%M`"
BuildName="PicoVR_v${Version}_B${BuildNumber}-`date +%Y%m%d`_Release.ipa"
cd "`echo ${0%/*}`"

#上传至蒲公英并下载二维码
curl -F "file=@Picovr.ipa" -F "uKey=f6e53bf36e08f8f15f73f3efa6d65fa4" -F "_api_key=16c38543300528d47c93a405f52396c2" http://www.pgyer.com/apiv1/app/upload | awk -F \" '{print $80}' | xargs curl -o QRCode_v${Version}_B${BuildNumber}.png

echo "文件成功上传至蒲公英并下载二维码：QRCode_v${Version}_B${BuildNumber}.png"

mkdir -p ${BuildDir}/{ipa,QRCode}
mv Picovr.ipa ${BuildDir}/ipa/${BuildName}
mv QRCode_v${Version}_B${BuildNumber}.png ${BuildDir}/QRCode/

#上传至BuildBrowser
lftp << EOF
open ftp://neil.qiao:qiao@Pico123@10.10.194.14:8021
cd builds/qa/iwing/iWing/
mirror -R ${Branch}/
close
bye
EOF

echo "任意键继续..."
char=`get_char`

